// This example shows how change the update rate of an existing OPC XML-DA subscription. using System; using System.Threading; using OpcLabs.EasyOpc.DataAccess; using OpcLabs.EasyOpc.DataAccess.OperationModel; namespace DocExamples.DataAccess.Xml { class ChangeItemSubscription { public static void Main1Xml() { // Instantiate the client object. using (var client = new EasyDAClient()) { client.ItemChanged += client_ItemChanged; Console.WriteLine("Subscribing..."); int handle = client.SubscribeItem( "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Int", 2000, state: null); Console.WriteLine("Waiting for 20 seconds..."); Thread.Sleep(20 * 1000); Console.WriteLine("Changing subscription..."); client.ChangeItemSubscription(handle, new DAGroupParameters(500)); Console.WriteLine("Waiting for 10 seconds..."); Thread.Sleep(10 * 1000); Console.WriteLine("Unsubscribing..."); client.UnsubscribeAllItems(); Console.WriteLine("Waiting for 10 seconds..."); Thread.Sleep(10 * 1000); } } // Item changed event handler static void client_ItemChanged(object sender, EasyDAItemChangedEventArgs e) { if (e.Succeeded) Console.WriteLine(e.Vtq); else Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief); } } }
# This example shows how change the update rate of an existing OPC XML-DA subscription. # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc import time # Import .NET namespaces. from OpcLabs.EasyOpc import * from OpcLabs.EasyOpc.DataAccess import * # Item changed event handler def itemChanged(sender, e): if e.Succeeded: print(e.Vtq) else: print('*** Failure: ', e.ErrorMessageBrief, sep='') # Instantiate the client object. client = EasyDAClient() client.ItemChanged += itemChanged print('Subscribing item...') handle = IEasyDAClientExtension.SubscribeItem(client, ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'), DAItemDescriptor('Dynamic/Analog Types/Int'), DAGroupParameters(2000), None) # state print('Processing item change notifications for 20 seconds...') time.sleep(20) print('Changing item subscription...') IEasyDAClientExtension.ChangeItemSubscription(client, handle, DAGroupParameters(500)) print('Processing item change notifications for 10 seconds...') time.sleep(10) print('Unsubscribing item...') IEasyDAClientExtension.UnsubscribeItem(client, handle) print('Waiting for 10 seconds...') time.sleep(10) client.ItemChanged -= itemChanged print('Finished.')
' This example shows how change the update rate of an existing OPC XML-DA subscription. Imports System.Threading Imports OpcLabs.EasyOpc.DataAccess Imports OpcLabs.EasyOpc.DataAccess.OperationModel Namespace DataAccess.Xml Partial Friend Class ChangeItemSubscription Public Shared Sub Main1Xml() Using client = New EasyDAClient() AddHandler client.ItemChanged, AddressOf client_ItemChanged Console.WriteLine("Subscribing...") Dim handle As Integer = client.SubscribeItem( "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Dynamic/Analog Types/Int", 2000, state:=Nothing) Console.WriteLine("Waiting for 20 seconds...") Thread.Sleep(20 * 1000) Console.WriteLine("Changing subscription...") client.ChangeItemSubscription(handle, New DAGroupParameters(500)) Console.WriteLine("Waiting for 10 seconds...") Thread.Sleep(10 * 1000) Console.WriteLine("Unsubscribing...") client.UnsubscribeAllItems() Console.WriteLine("Waiting for 10 seconds...") Thread.Sleep(10 * 1000) End Using End Sub ' Item changed event handler Private Shared Sub client_ItemChanged(ByVal sender As Object, ByVal e As EasyDAItemChangedEventArgs) If e.Succeeded Then Console.WriteLine(e.Vtq) Else Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief) End If End Sub End Class End Namespace
Copyright © 2004-2023 CODE Consulting and Development, s.r.o., Plzen. All rights reserved. Web page: www.opclabs.com
Send Documentation Feedback. Resources: Knowledge Base. Technical support: Online Forums, FAQ.